<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>审批客户诉求</title>
<link rel="stylesheet" type="text/css" href=${pageContext.servletContext.contextPath}/themes/default/easyui.css>   
<link rel="stylesheet" type="text/css" href=${pageContext.servletContext.contextPath}/themes/icon.css> 
<link rel="stylesheet" type="text/css" href=${pageContext.servletContext.contextPath}/themes/bootstrap/easyui.css>  
<script type="text/javascript" src=${pageContext.servletContext.contextPath}/js/jquery.min.js></script>   
<script type="text/javascript" src=${pageContext.servletContext.contextPath}/js/jquery.easyui.min.js></script> 
<script type="text/javascript" src=${pageContext.servletContext.contextPath}/js/easyui-lang-zh_CN.js></script>
</head>
<script>
$(function(){
	
	//审批窗口
	$('#win').window({    
	    width:400,    
	    height:250,
	    collapsible:false,
	    minimizable:false,
	    maximizable:false,
	    closed:true,
	    title:'审批窗口'
	});
	//未审批诉求数据表格
	$('#dg').datagrid({    
	    url:'${pageContext.servletContext.contextPath}/checkRequests',   
	    columns:[[  
	        {field:'ck',checkbox:true,width:100},
	        {field:'rid',title:'诉求id号',width:100,hidden:true},   
	        {field:'oid',title:'菜单id号',width:100},    
	        {field:'fname',title:'菜品名',width:100},    
	        {field:'rcontent',title:'诉求内容',width:100},    
	        {field:'rcount',title:'诉求数量',width:100},
	        {field:'rstate',title:'审批状态',width:100},
	        {field:'uname',title:'审批人',width:100},
	        {field:'rtime',title:'审批时间',width:180},    
	    ]],
	    toolbar: [{
			iconCls: 'icon-edit',
			text:'审批',
			handler: function(){
				$('#rid').textbox('clear');
				var selections=$('#dg').datagrid('getSelections');
				if(selections.length!=1){
					$.messager.show({
						title:'提示消息',
						msg:'请选择要审批的一行数据',
						timeout:5000,
					});

				}else{
					var  s = selections[0];
					 var rowIndex = $('#dg').datagrid('getRowIndex', s);
					 temprid=s.rid;
					 $("#rowIndex").textbox('setText',rowIndex+1);
					 $("#fname").textbox('setText',s.fname);
					 $('#win').window({
						closed:false,
					})
				}
				
			}
		}],
		striped:true,
	    rownumbers:true,
	    pagination:true,
	    pageSize:5,
		pageList:[5,10,15,20],
		onLoadSuccess: function () {   //隐藏表头的checkbox
             $("#dg").parent().find("div .datagrid-header-check").children("input[type=\"checkbox\"]").eq(0).attr("style", "display:none;");
         }

	});  
	
	//更新审批状态请求
	$('#submit').click(function(){
		$('#win').window({
			closed:true,
		});
		var selections=$('#dg').datagrid('getSelections');
    	var  s = selections[0];
		$.ajax({
		url:'${pageContext.servletContext.contextPath}/updateCheckState',
		dataType : "json",
		async : true,
		data : {
			"requestid" : s.rid,
			"checkstate":$('#rstate').val()
		},
		type : "post",
		success:function(data){  
		    //	var  m=eval("("+data+")");
		        if(data.date) {
		        var selections=$('#dg').datagrid('getSelections');
		    	var  s = selections[0];
		    	$('#dg').datagrid('updateRow',{
		    		index: $('#dg').datagrid('getRowIndex', s),
		    		row: {
		    			rstate:$('#rstate').val(),
		    			rtime:data.date
		    		}
		    	});
		    
		    }
		        }
		})
	})
	//取消按钮
	$('#cancel').click(function(){
    	//$('#rid').textbox('clear');
    	$('#win').window({
			closed:true,
		})
    })
//审批状态下拉菜单  
	$('#rstate').combo({    
	    required:true,    
	    multiple:true,
	    panelHeight:60
	    
	}); 
})
</script>
<body>
<table id="dg"></table>
<div id="win">
<div id="ff">  
     <div>   
        <label for="name">菜品索引:</label>   
        <input id="rowIndex" class="easyui-textbox" />   
    </div> 
     <div>   
        <label for="name">菜品名称:</label>   
        <input id="fname" class="easyui-textbox" />   
    </div>

    <div>   
         <label for="name">审批状态:</label>  
        <select id="rstate" class="easyui-combobox" name="checkstate">
        <option value="审批通过">审批通过</option>
        <option value="审批未通过">审批未通过</option>
        </select> 
           
    </div> 
    <button id="submit">确定</button>
    <button id="cancel">取消</button>
</div> 

</div> 
</body>
</html>